﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Home_Platforms : System.Web.UI.Page
{
    public List<PlatformEntity> platforms { set; get; }
    UserEntity currentUser;
    public PlatformAdapter platAdapter;
    public LanguageManage Language;
    public long platformID;
    public string title = "Platforms";

    public PlatformEntity currentPlatform = new PlatformEntity();
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check Login
        currentUser = UserManager.Instance.Getuser();
        if (!currentUser.isLogin)
            Response.Redirect("~/Login.aspx");

        platAdapter = new PlatformAdapter();
        Platform1.platforms = platAdapter.getListPlatform();
        Language = new LanguageManage();
        
        btn_create.Text = Language["AddNewPlatform"];

        if (Request.QueryString["platformid"] != null)
        {

            title = "EditPlatform";
            btn_create.Text = Language["Update"];
            platformID = Convert.ToInt32(Request.QueryString["platformid"]);
            currentPlatform = platAdapter.GetPlatformByID(platformID)[0];
        }
        Session["menu_current"] = Session["menu_id"];
        Session["menu_id"] = "platform";
    }

    protected void btn_create_Click(object sender, EventArgs e)
    {
        
         try
        {
            currentPlatform.Name = Request.Form["txtName"].ToString();
            currentPlatform.Description = Request.Form["txtName"].ToString();
        
            if (Request.QueryString["platformid"] == null)
            {
              
                platAdapter.createPlatform(currentPlatform);
                Response.Redirect("~/Home/Platforms.aspx");
            }
            else
            {
               
                currentPlatform.ID = platformID;
                platAdapter.UpdatePlatform(currentPlatform);
                Response.Redirect("~/Home/Platforms.aspx");
            }
        }
        catch (Exception)
        {

            throw;
        }
 
        Response.Redirect("~/Home/Platforms.aspx");
    
    }
}